import 'package:finance_app/src/entities/journal_entry_detail_entity.dart';
import 'package:finance_app/src/entities/ocr_attachment_entity.dart';

journalEntryDetailEntityFromJson(JournalEntryDetailEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['number'] != null) {
		data.number = json['number'].toString();
	}
	if (json['ref_number'] != null) {
		data.refNumber = json['ref_number'].toString();
	}
	if (json['transaction_id'] != null) {
		data.transactionId = json['transaction_id'] is String
				? int.tryParse(json['transaction_id'])
				: json['transaction_id'].toInt();
	}
	if (json['transaction_type'] != null) {
		data.transactionType = json['transaction_type'].toString();
	}
	if (json['journal_ref_id'] != null) {
		data.journalRefId = json['journal_ref_id'] is String
				? int.tryParse(json['journal_ref_id'])
				: json['journal_ref_id'].toInt();
	}
	if (json['currency'] != null) {
		data.currency = json['currency'].toString();
	}
	if (json['amount'] != null) {
		data.amount = json['amount'] is String
				? int.tryParse(json['amount'])
				: json['amount'].toInt();
	}
	if (json['default_currency'] != null) {
		data.defaultCurrency = json['default_currency'].toString();
	}
	if (json['default_amount'] != null) {
		data.defaultAmount = json['default_amount'] is String
				? int.tryParse(json['default_amount'])
				: json['default_amount'].toInt();
	}
	if (json['rate'] != null) {
		data.rate = json['rate'] is String
				? int.tryParse(json['rate'])
				: json['rate'].toInt();
	}
	if (json['memo'] != null) {
		data.memo = json['memo'];
	}
	if (json['date'] != null) {
		data.date = json['date'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['deleted_at'] != null) {
		data.deletedAt = json['deleted_at'].toString();
	}
	if (json['add_from'] != null) {
		data.addFrom = json['add_from'].toString();
	}
	if (json['journalDetail'] != null) {
		data.journalDetail = (json['journalDetail'] as List).map((v) => JournalEntryDetailJournalDetail().fromJson(v)).toList();
	}
	if (json['attachments'] != null) {
		data.attachments = (json['attachments'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	if (json['attachments_info'] != null) {
		data.attachmentsInfo = (json['attachments_info'] as List).map((v) => OcrAttachmentEntity().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> journalEntryDetailEntityToJson(JournalEntryDetailEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['number'] = entity.number;
	data['ref_number'] = entity.refNumber;
	data['transaction_id'] = entity.transactionId;
	data['transaction_type'] = entity.transactionType;
	data['journal_ref_id'] = entity.journalRefId;
	data['currency'] = entity.currency;
	data['amount'] = entity.amount;
	data['default_currency'] = entity.defaultCurrency;
	data['default_amount'] = entity.defaultAmount;
	data['rate'] = entity.rate;
	data['memo'] = entity.memo;
	data['date'] = entity.date;
	data['status'] = entity.status;
	data['deleted_at'] = entity.deletedAt;
	data['add_from'] = entity.addFrom;
	data['journalDetail'] =  entity.journalDetail?.map((v) => v.toJson())?.toList();
	data['attachments'] =  entity.attachments?.map((v) => v.toJson())?.toList();
	data['attachments_info'] =  entity.attachmentsInfo?.map((v) => v.toJson())?.toList();
	return data;
}

journalEntryDetailJournalDetailFromJson(JournalEntryDetailJournalDetail data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['journal_id'] != null) {
		data.journalId = json['journal_id'] is String
				? int.tryParse(json['journal_id'])
				: json['journal_id'].toInt();
	}
	if (json['coa_account_detail_id'] != null) {
		data.coaAccountDetailId = json['coa_account_detail_id'] is String
				? int.tryParse(json['coa_account_detail_id'])
				: json['coa_account_detail_id'].toInt();
	}
	if (json['coa_account_detail_name'] != null) {
		data.coaAccountDetailName = json['coa_account_detail_name'].toString();
	}
	if (json['crdr_nature'] != null) {
		data.crdrNature = json['crdr_nature'].toString();
	}
	if (json['f_currency'] != null) {
		data.fCurrency = json['f_currency'].toString();
	}
	if (json['f_dr_amount'] != null) {
		data.fDrAmount = json['f_dr_amount'] is String
				? int.tryParse(json['f_dr_amount'])
				: json['f_dr_amount'].toInt();
	}
	if (json['f_cr_amount'] != null) {
		data.fCrAmount = json['f_cr_amount'] is String
				? int.tryParse(json['f_cr_amount'])
				: json['f_cr_amount'].toInt();
	}
	if (json['currency'] != null) {
		data.currency = json['currency'].toString();
	}
	if (json['dr_amount'] != null) {
		data.drAmount = json['dr_amount'] is String
				? num.tryParse(json['dr_amount'])
				: json['dr_amount'];
	}
	if (json['cr_amount'] != null) {
		data.crAmount = json['cr_amount'] is String
				? num.tryParse(json['cr_amount'])
				: json['cr_amount'];
	}
	if (json['displayBalance'] != null) {
		data.displayBalance = json['displayBalance'] is String
				? int.tryParse(json['displayBalance'])
				: json['displayBalance'].toInt();
	}
	return data;
}

Map<String, dynamic> journalEntryDetailJournalDetailToJson(JournalEntryDetailJournalDetail entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['journal_id'] = entity.journalId;
	data['coa_account_detail_id'] = entity.coaAccountDetailId;
	data['coa_account_detail_name'] = entity.coaAccountDetailName;
	data['crdr_nature'] = entity.crdrNature;
	data['f_currency'] = entity.fCurrency;
	data['f_dr_amount'] = entity.fDrAmount;
	data['f_cr_amount'] = entity.fCrAmount;
	data['currency'] = entity.currency;
	data['dr_amount'] = entity.drAmount;
	data['cr_amount'] = entity.crAmount;
	data['displayBalance'] = entity.displayBalance;
	return data;
}